#include "Print_Data_Func.h"
#include "windows.h"
#include <time.h>

namespace INHOUSE{

	int Print_ReqData_To_File(const CString & contents, int tickerId){
	
	SYSTEMTIME time;
	GetSystemTime(&time);	
	std::fstream myfile;
//	time_t rawtime;
//	struct tm * ptm;
//	time ( &rawtime );
//	ptm = gmtime ( &rawtime );
	CString str1;
	str1.Format( "%s_%d%d%d_%i.txt",FILE_NAME_COMMON.c_str(), time.wYear, time.wMonth, time.wDay, tickerId);
	myfile.open(str1, std::fstream::in | std::fstream::out | std::fstream::app);
//	myfile << ptm->tm_year<<'/'<<ptm->tm_mon<<'/'<<ptm->tm_mday<<'\t'<<ptm->tm_hour<<':'<<ptm->tm_min<<':'<<ptm->tm_sec<<'\t'<<contents<<'\n';


	myfile <<time.wYear<<'/'<<time.wMonth<<'/'<<time.wDay<<'\t'<<time.wHour<<':'<<time.wMinute<<':'<<time.wSecond<<'.'<<int(time.wMilliseconds/100)<<'\t'<<contents<<'\n';
	

	myfile.close();

	return 1;
}

void Auto_Get_Contract_reqMKTDATA(std::vector<std::pair<Contract, long>> & Contract_Vec, IBString & genericTicks){
	
		Contract_Vec.clear();
		
//		genericTicks = "100,101,104,105,106,107,165,221,225,233,236,258,293,294,295,318";
		genericTicks = "104";
		//,105,165,221,225,233,236,258,293,294,295,318";
		

		//for now, we define all CL ID begins with 1;
		//we will use 1~999 for market index, like CL = 1 (crude oil), GC = 2 (gold);
		//in the future we may change our contract naming, for example, use standard financial contract id, like CUSIP
		
		long CL_Product_ID = 1;   
		int CL_NUMSTRIKES = 100;
		int CL_MONTH = 1;
		int CL_SCALER = 100;

		long GC_Product_ID = 2;
		int GC_NUMSTRIKES = 100;
		int GC_MONTH = 1;
		int GC_SCALER = 10;

		long KC_Product_ID = 3;
		int KC_NUMSTRIKES = 40;
		int KC_MONTH = 3;
		int KC_SCALER = 100;
		
		Contract_Vec.reserve(CL_MONTH * (CL_NUMSTRIKES*2+1) + GC_MONTH * (GC_NUMSTRIKES*2+1) + KC_MONTH * (KC_NUMSTRIKES*2+1)); //for each product, each month, we have num_strike * 2 + 1 contract, (call/put + future)
		
		//our id format:
				//Product_ID/Expiration/CP/STRIKE
				//Expiration has two digits, from 01 to 99, covering 201201 to 201204. like 201201->01. 201202->02, 201301->13, 201302->14...
				//Strike has five digits, for example, CL 90 call/put is 9000; 0000 is future
				//scale the strike by 100
				//Call->positive number
				//Put->negative number
		{
			Contract a;
			a.symbol = "CL";
			a.secType = "FOP";


			long Expirary = (2012 - 2012)*12 + 12;
			a.expiry = "201212";
			a.currency = "USD";
			a.exchange = "NYMEX";
			a.primaryExchange = "NYMEX";
			long ID_PREFIX = (CL_Product_ID * 100 + Expirary) * 100000;

			for(int i = 0; i < CL_NUMSTRIKES; ++i){
				a.strike = 40 + i;
				a.right = "Call";
				

				//the reason for using the above format is because ID is long type so ...
				long tmp_ID =  ID_PREFIX + a.strike * CL_SCALER;
				Contract_Vec.push_back(std::pair<Contract,long>(a, tmp_ID));
				a.right = "Put";
				Contract_Vec.push_back(std::pair<Contract,long>(a, -tmp_ID));
			}
			//adding underline future
			a.secType = "FUT";
			Contract_Vec.push_back(std::pair<Contract,long>(a, ID_PREFIX));
		}

		{
			Contract a;
			a.symbol = "GC";
			a.secType = "FOP";

			long Expirary = (2012 - 2012)*12 + 12;
			a.expiry = "201210";
			a.currency = "USD";
			a.exchange = "NYMEX";
			a.primaryExchange = "NYMEX";
			long ID_PREFIX = (GC_Product_ID * 100 + Expirary) * 100000;

			for(int i = 0; i < GC_NUMSTRIKES; ++i){
				a.strike = 1000 + i*10;
				a.right = "Call";
				

				//the reason for using the above format is because ID is long type so ...
				long tmp_ID =  ID_PREFIX + a.strike * GC_SCALER;
				Contract_Vec.push_back(std::pair<Contract,long>(a, tmp_ID));
				a.right = "Put";
				Contract_Vec.push_back(std::pair<Contract,long>(a, -tmp_ID));
			}
			//adding underline future
			a.secType = "FUT";
			Contract_Vec.push_back(std::pair<Contract,long>(a, ID_PREFIX));
		}

		{

			
			Contract a;
			a.symbol = "KC";
			a.secType = "FOP";

			// KC first month
			long Expirary = (2012 - 2012)*12 + 10;
			a.expiry = "201210";
			a.currency = "USD";
			a.exchange = "NYBOT";
			a.primaryExchange = "NYBOT";
			long ID_PREFIX = (KC_Product_ID * 100 + Expirary) * 100000;

			for(int i = 0; i < KC_NUMSTRIKES; ++i){
				a.strike = 1 + double(i)/20.0;
				a.right = "Call";
				

				//the reason for using the above format is because ID is long type so ...
				long tmp_ID =  ID_PREFIX + a.strike * KC_SCALER;
				Contract_Vec.push_back(std::pair<Contract,long>(a, tmp_ID));
				a.right = "Put";
				Contract_Vec.push_back(std::pair<Contract,long>(a, -tmp_ID));
			}

			// KC second month
			Expirary = (2012 - 2012)*12 + 11;
			a.expiry = "201211";
			a.currency = "USD";
			a.exchange = "NYBOT";
			a.primaryExchange = "NYBOT";
			ID_PREFIX = (KC_Product_ID * 100 + Expirary) * 100000;

			for(int i = 0; i < KC_NUMSTRIKES; ++i){
				a.strike = 1 + double(i)/20.0;
				a.right = "Call";
				

				//the reason for using the above format is because ID is long type so ...
				long tmp_ID =  ID_PREFIX + a.strike * KC_SCALER;
				Contract_Vec.push_back(std::pair<Contract,long>(a, tmp_ID));
				a.right = "Put";
				Contract_Vec.push_back(std::pair<Contract,long>(a, -tmp_ID));
			}

			//KC third month
			Expirary = (2012 - 2012)*12 + 12;
			a.expiry = "201212";
			a.currency = "USD";
			a.exchange = "NYBOT";
			a.primaryExchange = "NYBOT";
			ID_PREFIX = (KC_Product_ID * 100 + Expirary) * 100000;

			for(int i = 0; i < KC_NUMSTRIKES; ++i){
				a.strike = 1 + double(i)/20.0;
				a.right = "Call";
				

				//the reason for using the above format is because ID is long type so ...
				long tmp_ID =  ID_PREFIX + a.strike * KC_SCALER;
				Contract_Vec.push_back(std::pair<Contract,long>(a, tmp_ID));
				a.right = "Put";
				Contract_Vec.push_back(std::pair<Contract,long>(a, -tmp_ID));
			}


			//adding underline future
			a.secType = "FUT";
			a.expiry = "201212";
			Contract_Vec.push_back(std::pair<Contract,long>(a, ID_PREFIX));
		}
}
		




};